package com.eastfair.auth.exceptioncode;

import com.eastfair.annotation.base.LanguageTypeEnum;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.exception.code.BaseExceptionCode;

/**
 * 场馆服务后台错误码.
 * AABBBCCC   AA(12)  系统编号   BBB 模块    CCC 具体异常
 * 模块编号
 * 展会：001
 * 服务商：002
 * 服务：003
 *
 * @author dqq
 * @date 2022 /7/14
 */
public enum AuthServiceExceptionCode implements BaseExceptionCode {

    /*
     *********************展会********************
     */
    USER_AGAIN(1300001, "账号已存在", ""),

    ROLE_AGAIN(1300002, "角色已存在", ""),

    USER_NO_SYSTEM(1300003, "账户不在系统里", ""),

    USER_IN_SYSTEM(1300004, "账户在该系统里", ""),

    USER_IN_OTHER_TEAM(1300006, "账户已绑定其他服务商", ""),


    PHONE_CODE_ERROR(16001005, "验证码验证失败", ""),


    /**
     * 角色菜单不能为空
     */
    NOT_ROLE_MENU_NULL(16001003,"角色菜单不能为空",""),

    /**
     * 角色菜单不能为空
     */
    PRODUCE_ID_NULL(16001004,"服务商id不能为空",""),

    ;

    private final int code;
    /**
     * 中文消息
     */
    private String msg;
    /**
     * 英文消息
     */
    private String enMsg;

    AuthServiceExceptionCode(int code, String msg, String enMsg) {
        this.code = code;
        this.msg = msg;
        this.enMsg = enMsg;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        //中英文切换
        if (LanguageTypeEnum.CN.name().equals(ContextUtil.getLanguageType())) {
            //中文
            return msg;
        } else if (LanguageTypeEnum.EN.name().equals(ContextUtil.getLanguageType())) {
            //英文
            return enMsg;
        }
        return msg;
    }


    /**
     * Build venue booking exception code.
     *
     * @param msg   the msg
     * @param param the param
     * @return the venue booking exception code
     */
    public AuthServiceExceptionCode build(String msg, Object... param) {
        this.msg = String.format(msg, param);
        return this;
    }

    /**
     * Param venue booking exception code.
     *
     * @param param the param
     * @return the venue booking exception code
     */
    public AuthServiceExceptionCode param(Object... param) {
        msg = String.format(msg, param);
        return this;
    }
}